package com.gaoji_android09;

import android.media.AudioManager;
import android.media.SoundPool;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

/**
 * SoundPool 播放短的声音 可以通知支持多个声音同时发声！
 *
 *  1将声音添加到声音池中
 *  2具体的播放
 */
public class MainActivity extends AppCompatActivity {

    private SoundPool soundPool;
    private int one;
    private int two;
    private int three;
    private int four;
    private int five;
    private int six;
    private int seven;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        /**
         * 参数1  maxNum 支持同时发生的最大数
         * 参数2  声音乐类型
         * 参数3  音质
         *
         */
        soundPool=new SoundPool(7, AudioManager.STREAM_MUSIC,0);

        /**
         * 参数1  上下文对象
         * 参数2  资源id
         * 参数3  优先级
         */
        one = soundPool.load(this, R.raw.one, 1);
        two = soundPool.load(this, R.raw.two, 1);
        three = soundPool.load(this, R.raw.three, 1);
        four = soundPool.load(this, R.raw.four, 1);
        five = soundPool.load(this, R.raw.five, 1);
        six = soundPool.load(this, R.raw.six, 1);
        seven = soundPool.load(this, R.raw.seven, 1);

    }

    public void btnClick(View view) {

        switch (view.getId()) {
            case R.id.btn_1:
                /**
                 * int soundID,
                 * float leftVolume,
                 * float rightVolume,
                 * int priority, int loop,
                 * float rate
                 */
                soundPool.play(one,1,1,1,0,1);
                break;
            case R.id.btn_2:
                soundPool.play(two,1,1,1,0,1);
                break;
            case R.id.btn_3:
                soundPool.play(three,1,1,1,0,1);
                break;
            case R.id.btn_4:
                soundPool.play(four,1,1,1,0,1);
                break;
            case R.id.btn_5:
                soundPool.play(five,1,1,1,0,1);
                break;
            case R.id.btn_6:
                soundPool.play(six,1,1,1,0,1);
                break;
            case R.id.btn_7:
                soundPool.play(seven,1,1,1,0,1);
                break;
        }
    }
}
